import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  /// 1.一旦设置了主体，那么应用程序中的某些Widget，就会直接使用主题的样式
  /// 2.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        //1.亮度
        brightness: Brightness.light,
        //2.primarySwatch传人的不是Color，而是MaterialColor(包含了primaryColor和accentColor)
        primarySwatch: Colors.red,
        //3. 导航和TabBar的颜色
        primaryColor: Colors.teal,
        //4. 单独设置floatingActionButton\Switch
        accentColor: Colors.orange,
        //5.Button的主题
        buttonTheme: ButtonThemeData(
            height: 25, minWidth: 10, buttonColor: Colors.yellow),
        //6.Card主题
        cardTheme: CardTheme(
          color: Colors.greenAccent,
          elevation: 10,
          shape: BorderDirectional(top: BorderSide(color: Colors.teal)),
          clipBehavior: Clip.antiAlias,
        ),
        //7.Text主题
        textTheme: TextTheme(
          bodyText1: TextStyle(fontSize: 20),
          bodyText2: TextStyle(fontSize: 30, color: Colors.red),
          headline1: TextStyle(fontSize: 14),
          headline2: TextStyle(fontSize: 16),
          headline3: TextStyle(fontSize: 18),
          headline4: TextStyle(fontSize: 20),
          headline5: TextStyle(fontSize: 22),
        ),
      ),
      debugShowCheckedModeBanner: false,
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Flutter Demo'),
        ),
        body: Center(
            child: Column(
              children: [
                Text('Hello Flutter'),
                Text('Hello Flutter', style: TextStyle(fontSize: 14)),
                Text('Hello Flutter', style: TextStyle(fontSize: 20)),
                Text('Hello Flutter', style: Theme.of(context).textTheme.bodyText1),
                Switch(
                    value: true,
                    onChanged: (value) {
                      print(value);
                    }),
                CupertinoSwitch(
                    value: true, activeColor: Colors.red, onChanged: (value) {}),
                RaisedButton(child: Text('R'), onPressed: () {}),
                Card(child: Text('你好啊，zs', style: TextStyle(fontSize: 30)))
              ],
            )),
        bottomNavigationBar: BottomNavigationBar(items: [
          BottomNavigationBarItem(title: Text('首页'), icon: Icon(Icons.home)),
          BottomNavigationBarItem(
              title: Text('设置'), icon: Icon(Icons.settings)),
        ]),
        floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (ctx) {
                return HYDetailPage();
              }));
            }),
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat);
  }
}

class HYDetailPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Theme(
      // data: ThemeData(primaryColor: Colors.purple),
      data: Theme.of(context)
          .copyWith(primaryColor: Colors.purple, accentColor: Colors.pink),
      child: Scaffold(
        appBar: AppBar(
          title: Text('详情页'),
          // backgroundColor: Colors.red,
        ),
        body: Center(
          child: Text('Hello Flutter'),
        ),
        floatingActionButton: Theme(
            data: Theme.of(context).copyWith(
                colorScheme: Theme.of(context)
                    .colorScheme
                    .copyWith(secondary: Colors.pink)),
            child: FloatingActionButton(
                child: Icon(Icons.pets), onPressed: () {})),
      ),
    );
  }
}
